#pragma once

VOID unit_finalize(JSContext *cx, JSObject *obj);
INT unit_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
INT unit_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);

#define DEFFNC(f) INT f (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);

DEFFNC(unit_getNext)
DEFFNC(unit_command)
DEFFNC(unit_build)

#undef DEFFNC

/**********************************************************

					Classes/Objects/Methods

 **********************************************************/

static JSClass unit_class = {
    "unitunit",	JSCLASS_HAS_PRIVATE,
    JS_PropertyStub, JS_PropertyStub, unit_getProperty, unit_setProperty,
    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, unit_finalize,
    NULL, NULL, 
};

enum unit_tinyid {
	UNIT_NAME,
	UNIT_HP,
	UNIT_HPMAX,
	UNIT_ID1, 
	UNIT_ID2,
	UNIT_CLASSID,
	UNIT_OWNERSLOT,
	UNIT_ISHERO,
	UNIT_X,
	UNIT_Y,
	UNIT_ANIMATIONID,
};

static JSPropertySpec unit_props[] = {
	{"name",		UNIT_NAME,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"hp",			UNIT_HP,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"hpmax",		UNIT_HPMAX,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"id1",			UNIT_ID1,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"id2",			UNIT_ID2,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"classid",		UNIT_CLASSID,	JSPROP_ENUMERATE | JSPROP_READONLY},
	{"ownerslot",	UNIT_OWNERSLOT,	JSPROP_ENUMERATE | JSPROP_READONLY},
	{"ishero",		UNIT_ISHERO,	JSPROP_ENUMERATE | JSPROP_READONLY},
	{"x",			UNIT_X,			JSPROP_ENUMERATE | JSPROP_READONLY},
	{"y",			UNIT_Y,			JSPROP_ENUMERATE | JSPROP_READONLY},
	{"animationid", UNIT_ANIMATIONID,JSPROP_ENUMERATE | JSPROP_READONLY},
	{0},
};

static JSFunctionSpec unit_methods[] = {
	{"getNext",			unit_getNext,		0},
	{"command",			unit_command,		2},
	{"build",			unit_build,			3},
	{0},
};

struct myUnit
{
	DWORD _dwPrivateType;
	DWORD dwId1;
	DWORD dwId2;
	DWORD dwClassId;
	DWORD dwOwnerSlot;
	DWORD dwIndex;
	CHAR szName[64];
};
